package com.cskaoyan.mall.product.controller;

import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.common.util.SealResult;
import com.cskaoyan.mall.product.dto.FirstLevelCategoryDTO;
import com.cskaoyan.mall.product.dto.SecondLevelCategoryDTO;
import com.cskaoyan.mall.product.dto.ThirdLevelCategoryDTO;
import com.cskaoyan.mall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @GetMapping("/admin/product/getCategory1")
    public Result getFirstLevelCategory(){
        List<FirstLevelCategoryDTO> firstLevelCategory = categoryService.getFirstLevelCategory();
        return SealResult.parseResult(firstLevelCategory);

    }
    @GetMapping("/admin/product/getCategory2/{category1Id}")
    public Result getSecondLevelCategory(@PathVariable("category1Id") Long category1Id){
        List<SecondLevelCategoryDTO> secondLevelCategory = categoryService.getSecondLevelCategory(category1Id);

        return  SealResult.parseResult(secondLevelCategory);
    }
    @GetMapping("/admin/product/getCategory3/{category2Id}")
    public Result getThirdLevelCategory(@PathVariable("category2Id") Long category2Id){
        List<ThirdLevelCategoryDTO> thirdLevelCategory = categoryService.getThirdLevelCategory(category2Id);

        return  SealResult.parseResult(thirdLevelCategory);
    }

}
